﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.Threading;
using DAL.Dao;
using Auto;
using DataControl;

namespace AnTeWeiAutoService
{
    public partial class Form1 : Form
    {
        DataAccess da = new DataAccess();
        CommonHelp _CommonHelp = new CommonHelp();
        MessageDao _MessageDao = new MessageDao();
        public Form1()
        {
            InitializeComponent();

            backgroundWorker1.RunWorkerAsync();
            backgroundWorker2.RunWorkerAsync();
            backgroundWorker3.RunWorkerAsync();
        }

        /// <summary>
        /// 1.关闭需求单 2.挑选报价单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                try
                {
                    AutoLog.Debug("backgroundWorker1_DoWork", "开始运行");
                    //string strDateFrom = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd");  // 从1小时前获取，防止12点的数据会丢失
                    //string strTips = _MessageDao.GetTips("14", "vi");
                    //GetEXMC_EcgStructData(strDateFrom);
                    AutoCloseBid();
                    AutoChooseResponse();
                    Thread.Sleep(1000*60);
                    //GetEXMC_PictureData(strDateFrom);

                    //backgroundWorker1.ReportProgress(iCounter++);
                }
                catch (Exception ex)
                {
                    AutoLog.Debug("AutoService-backgroundWorker1_DoWork", ex.Message.ToString());
                }
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("关闭此程序会导致安特威无法正确获取数据，请慎重，如需取消请按“取消”按钮！", "慎重操作", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Cancel)
            {
                e.Cancel = true;
                return;
            }

            backgroundWorker1.CancelAsync();
            backgroundWorker2.CancelAsync();
            backgroundWorker3.CancelAsync();
        }

        private void AutoCloseBid()
        {
            try
            {
                AutoLog.Debug("AutoCloseBid", "开始自动关闭已到期需求");
                Dictionary<string, object> parm = new Dictionary<string, object>();
                parm.Add("@Parm", "");
                da.GetDataSetBySPName("SP_AutoCloseBid", parm);
            }
            catch (Exception ex)
            {
                AutoLog.Debug("自动关闭已到期需求出错", ex.Message.ToString());
            }

        }

        private void AutoChooseResponse()
        {
            try
            {
                AutoLog.Debug("AutoChooseResponse", "开始自动挑选报价单");
                //查询所有未汇总的询价单
                Dictionary<string, object> parm = new Dictionary<string, object>();
                parm.Add("@Parm", "");
                DataTable dtRequest = da.GetDataTableBySPName("SP_AutoChooseRequest", parm);

                if (dtRequest == null || dtRequest.Rows.Count == 0)
                {
                    AutoLog.Debug("AutoChooseResponse", "没有到期的报价单");
                    return;
                }

                //取出每条询价单，挑选报价单
                foreach (DataRow dr in dtRequest.Rows)
                {
                    string strFlag = "";
                    DataSet ds = new DataSet();
                    DataTable dtResult = GetReqIdAndLoginId(dr, ref strFlag, ref ds);
                    AutoLog.Debug("返回参数1", strFlag);
                    //intFlag:0.挑选成功 1.首次推送校验报价数失败，推送系统管理员 2.延迟后仍校验失败，推送管理人员,并将询价单关闭 3.首次推送后,有效价格校验失败，推送分供商
                    if (strFlag.Contains("0"))
                    {
                        AutoLog.Debug("AutoChooseResponse", "挑选完成，推送客户");
                        //挑选完成，推送客户
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "2";
                        Entry.tmfrom = "system";
                        
                        foreach (DataRow dr1 in dtResult.Rows)
                        {

                            #region 多语言
                                string strTip1 = "";
                                string strCountryLan = _MessageDao.GetUserCountryLan(dr1["RequestID"].ToString());

                                strTip1 = _MessageDao.GetTips("8", strCountryLan);
                            #endregion

                            Entry.tmTitle = strTip1;
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = _MessageDao.CreateMessageByRequestId(dr1["RequestID"].ToString(), Entry.tmType);

                            Entry.toType = "1";
                            Entry.toId = dr1["RequestID"].ToString();

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("RequestId", dr1["RequestID"].ToString());

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }
                        #endregion
                    }
                    if (strFlag.Contains("1"))
                    {//首次校验失败，推送管理人员
                        //没有合适的供应商,推送系统管理员
                        DataTable dtCount = ds.Tables["dtCount"];
                        AutoLog.Debug("AutoChooseResponse-dtCount", "首次校验失败，推送管理人员");
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "1";
                        Entry.tmfrom = "system";
                        Entry.tmto = "";
                        Entry.tmTitle = "报价数目存在异常，请处理";
                        Entry.tmMessage = _MessageDao.CreateMessageByDataTable(dtCount);

                        _CommonHelp.SendMessage(Entry, "2", new Dictionary<string, string>());

                        //没有合适的供应商,推送分供商，催促报价
                        Entry = new T_Message();
                        Entry.tmType = "3";
                        Entry.tmfrom = "system";
                        Entry.tmTitle = "请重新确认您的报价";

                        DataView dataView = dtCount.DefaultView;

                        DataTable dtCountDistinct = dataView.ToTable(true, "tauloginid");//注：其中ToTable（）的第一个参数为是否DISTINCT

                        //汇总推送
                        foreach (DataRow dr1 in dtCountDistinct.Rows)
                        {
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = _MessageDao.CreateMessageByRequestId("", "7");

                            DataRow[] row = dtCount.Select("tauloginid=" + dr1["tauloginid"].ToString());

                            string strReqDetailID = row[0]["ReqDetailID"].ToString();

                            //获取ResponseID
                            StringBuilder sql = new StringBuilder();
                            sql.AppendFormat(@"select t1.ResponseID 
                                            from T_ResponseDetail  t
                                            inner join T_Response t1 on t.ResponseID=t1.ResponseID
                                            where t.ReqDetailID='{0}' and t1.tauloginid='{1}'", strReqDetailID, dr1["tauloginid"].ToString());
                            DataTable dtRes = da.ExecuteDataTable(sql.ToString());

                            string strResponseID = dtRes.Rows[0]["ResponseID"].ToString();
                            //更新报价单状态，重新报价
                            string strSql = @"update T_Response set rowstatus=7
                            where ResponseID='{0}'";
                            strSql = string.Format(strSql, strResponseID);
                            da.ExcuteNoQuery(strSql);

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("ResponseId", strResponseID);

                            Entry.toType = "2";
                            Entry.toId = strResponseID;

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }

//                        foreach (DataRow dr1 in dtCount.Rows)
//                        {
//                            StringBuilder sql = new StringBuilder();
//                            sql.AppendFormat(@"select t1.ResponseID 
//                                            from T_ResponseDetail  t
//                                            inner join T_Response t1 on t.ResponseID=t1.ResponseID
//                                            where t.ReqDetailID='{0}' and t1.tauloginid='{1}'", dr1["ReqDetailID"].ToString(), dr1["tauloginid"].ToString());
//                            DataTable dtRes = da.ExecuteDataTable(sql.ToString());

//                            string strResponseID = dtRes.Rows[0]["ResponseID"].ToString();

//                            Entry.tmto = dr1["tauloginid"].ToString();

//                            Entry.tmMessage = _MessageDao.CreateMessageByRequestId(dr1["ReqDetailID"].ToString(), "7");

//                            Dictionary<string, string> Parm = new Dictionary<string, string>();
//                            Parm.Add("ResponseId", strResponseID);

//                            Entry.toType = "2";
//                            Entry.toId = strResponseID;

//                            _CommonHelp.SendMessage(Entry, "3", Parm);
//                        }

                        //没有合适的供应商,推送客户，告知延迟
                        Entry = new T_Message();
                        Entry.tmType = "2";
                        Entry.tmfrom = "system";

                        StringBuilder sql1 = new StringBuilder();
                        sql1.AppendFormat(@"select t1.RequestID,t1.tauloginid
                                        from T_RequestDetail t
                                        inner join T_Request t1 on t.RequestID=t1.RequestID
                                        where t.ReqDetailID='{0}'", dtCount.Rows[0]["ReqDetailID"].ToString());
                        DataTable dtReq = da.ExecuteDataTable(sql1.ToString());

                        foreach (DataRow dr1 in dtReq.Rows)
                        {

                            #region 多语言
                            string strTip1 = "";
                            string strTip2 = "";
                            string strCountryLan = _MessageDao.GetUserCountryLan(dr1["RequestID"].ToString());

                            strTip1 = _MessageDao.GetTips("8", strCountryLan);
                            strTip2 = _MessageDao.GetTips("12", strCountryLan);

                            #endregion

                            Entry.tmTitle = strTip1;
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = strTip2;

                            Entry.toType = "1";
                            Entry.toId = dr1["RequestID"].ToString();

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("RequestId", dr1["RequestID"].ToString());

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }
                        #endregion
                    }
                    if (strFlag.Contains("3"))
                    {//首次校验失败，推送分供商
                        AutoLog.Debug("AutoChooseResponse", "进入价格错误推送");
                        DataTable dtPrice = ds.Tables["dtPrice"];
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "3";
                        Entry.tmfrom = "system";
                        Entry.tmTitle = "请重新确认您的报价";


                        DataView dataView = dtPrice.DefaultView;

                        DataTable dtPriceDistinct = dataView.ToTable(true, "tauloginid");//注：其中ToTable（）的第一个参数为是否DISTINCT


                        
                        
                       

                        //置报价单状态为7 标记为延时
                        foreach (DataRow dr1 in dtPrice.Rows)
                        {
                            StringBuilder sql = new StringBuilder();
                            sql.AppendFormat(@"select t1.ResponseID 
                                            from T_ResponseDetail  t
                                            inner join T_Response t1 on t.ResponseID=t1.ResponseID
                                            where t.ReqDetailID='{0}' and t1.tauloginid='{1}'", dr1["ReqDetailID"].ToString(), dr1["tauloginid"].ToString());
                            DataTable dtRes = da.ExecuteDataTable(sql.ToString());

                            string strResponseID = dtRes.Rows[0]["ResponseID"].ToString();
                            //更新报价单状态，重新报价
                            string strSql = @"update T_Response set rowstatus=7
                            where ResponseID='{0}'";
                            strSql = string.Format(strSql, strResponseID);
                            da.ExcuteNoQuery(strSql);

                            
                        }

                        //汇总推送
                        foreach (DataRow dr1 in dtPriceDistinct.Rows)
                        {
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = _MessageDao.CreateMessageByRequestId("", "6");

                            DataRow[] row = dtPrice.Select("tauloginid=" + dr1["tauloginid"].ToString());

                            string strReqDetailID = row[0]["ReqDetailID"].ToString();

                            //获取ResponseID
                            StringBuilder sql = new StringBuilder();
                            sql.AppendFormat(@"select t1.ResponseID 
                                            from T_ResponseDetail  t
                                            inner join T_Response t1 on t.ResponseID=t1.ResponseID
                                            where t.ReqDetailID='{0}' and t1.tauloginid='{1}'", strReqDetailID, dr1["tauloginid"].ToString());
                            DataTable dtRes = da.ExecuteDataTable(sql.ToString());

                            string strResponseID = dtRes.Rows[0]["ResponseID"].ToString();

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("ResponseId", strResponseID);

                            Entry.toType = "2";
                            Entry.toId = strResponseID;

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }


                        //没有合适的报价,推送客户，告知延迟
                        Entry = new T_Message();
                        Entry.tmType = "2";
                        Entry.tmfrom = "system";

                        StringBuilder sql1 = new StringBuilder();
                        sql1.AppendFormat(@"select t1.RequestID,t1.tauloginid
                                        from T_RequestDetail t
                                        inner join T_Request t1 on t.RequestID=t1.RequestID
                                        where t.ReqDetailID='{0}'", dtPrice.Rows[0]["ReqDetailID"].ToString());
                        DataTable dtReq = da.ExecuteDataTable(sql1.ToString());

                        foreach (DataRow dr1 in dtReq.Rows)
                        {

                            #region 多语言
                            string strTip1 = "";
                            string strTip2 = "";
                            string strCountryLan = _MessageDao.GetUserCountryLan(dr1["RequestID"].ToString());

                            strTip1 = _MessageDao.GetTips("8", strCountryLan);
                            strTip2 = _MessageDao.GetTips("12", strCountryLan);

                            #endregion

                            Entry.tmTitle = strTip1;
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = strTip2;

                            Entry.toType = "1";
                            Entry.toId = dr1["RequestID"].ToString();

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("RequestId", dr1["RequestID"].ToString());

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }
                        #endregion
                    }
                    if (strFlag.Contains("2"))
                    {//延迟后仍校验失败，推送管理人员,并将询价单关闭
                        DataTable dtCount = ds.Tables["dtCount"];
                        AutoLog.Debug("AutoChooseResponse", "延迟后仍校验失败，推送管理人员,并将询价单关闭");
                        //没有合适的供应商,推送系统管理员
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "1";
                        Entry.tmfrom = "system";
                        Entry.tmto = "";
                        Entry.tmTitle = "询价已超过48小时，无合适分供商，请处理";
                        Entry.tmMessage = _MessageDao.CreateMessageByDataTable(dtCount);

                        _CommonHelp.SendMessage(Entry, "2", new Dictionary<string, string>());
                        #endregion


                        string strSql = "";
                        strSql = @"update T_Request set rowstatus=9 where RequestID='{0}'";
                        strSql = string.Format(strSql, dr["RequestID"].ToString());

                        da.ExcuteNoQuery(strSql);

                        strSql = "";
                        strSql = @"update T_Response set rowstatus=8 where RequestID='{0}'";
                        strSql = string.Format(strSql, dr["RequestID"].ToString());

                        da.ExcuteNoQuery(strSql);

                        ////延迟后仍校验失败，推送客户，告知延迟
                        Entry = new T_Message();
                        Entry.tmType = "2";
                        Entry.tmfrom = "system";

                        StringBuilder sql1 = new StringBuilder();
                        sql1.AppendFormat(@"select t1.RequestID,t1.tauloginid
                                        from T_RequestDetail t
                                        inner join T_Request t1 on t.RequestID=t1.RequestID
                                        where t.ReqDetailID='{0}'", dtCount.Rows[0]["ReqDetailID"].ToString());
                        DataTable dtReq = da.ExecuteDataTable(sql1.ToString());

                        foreach (DataRow dr1 in dtReq.Rows)
                        {

                            #region 多语言
                            string strTip1 = "";
                            string strTip2 = "";
                            string strCountryLan = _MessageDao.GetUserCountryLan(dr1["RequestID"].ToString());

                            strTip1 = _MessageDao.GetTips("8", strCountryLan);
                            strTip2 = _MessageDao.GetTips("12", strCountryLan);
                            
                            #endregion

                            Entry.tmTitle = strTip1;
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = strTip2;

                            Entry.toType = "1";
                            Entry.toId = dr1["RequestID"].ToString();

                            Dictionary<string, string> Parm = new Dictionary<string, string>();
                            Parm.Add("RequestId", dr1["RequestID"].ToString());

                            _CommonHelp.SendMessage(Entry, "3", Parm);
                        }
                    }
                    
                }
            }
            catch (Exception ex)
            {
                AutoLog.Debug("AutoChooseResponse", ex.Message.ToString());
            }
        }

        /// <summary>
        /// 检查销售人员 关怀情况
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                AutoLog.Debug("backgroundWorker2_DoWork", "开始自动检查关怀、联系情况");

                    Dictionary<string, object> parm = new Dictionary<string, object>();
                    parm.Add("@Parm", "");
                    DataTable dtRequest = da.GetDataTableBySPName("SP_AutoConcern", parm);


                    //存在客户疏于关怀和联系，推送销售人员
                    if (dtRequest != null && dtRequest.Rows.Count > 0)
                    {
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "5";
                        Entry.tmfrom = "system";
                        Entry.tmTitle = "关怀提醒";
                        foreach (DataRow dr1 in dtRequest.Rows)
                        {
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = _MessageDao.CreateMessageByRequestId(dr1["targetID"].ToString(), Entry.tmType);

                            _CommonHelp.SendMessage(Entry, "3", new Dictionary<string, string>());
                        }


                        #endregion
                    }

 
                    Thread.Sleep(1000 * 60);

                    parm = new Dictionary<string, object>();
                    parm.Add("@Parm", "");
                    dtRequest = da.GetDataTableBySPName("SP_AutoPriceConcern", parm);


                    //存在客户疏于关怀和联系，推送销售人员
                    if (dtRequest != null && dtRequest.Rows.Count > 0)
                    {
                        #region 申明实体，并赋值
                        T_Message Entry = new T_Message();
                        Entry.tmType = "5";
                        Entry.tmfrom = "system";
                        Entry.tmTitle = "关怀提醒";
                        foreach (DataRow dr1 in dtRequest.Rows)
                        {
                            Entry.tmto = dr1["tauloginid"].ToString();

                            Entry.tmMessage = "客户"+dr1["targetID"].ToString()+"总采购金额已达标，请关怀。";

                            _CommonHelp.SendMessage(Entry, "3", new Dictionary<string, string>());
                        }

                        
                        #endregion
                    }

                    Thread.Sleep(1000 * 60);
            }
            catch (Exception ex)
            {
                AutoLog.Debug("开始自动检查关怀、联系情况出错", ex.Message.ToString());
            }

        }

        //intFlag:0.挑选成功 1.首次推送校验报价数失败，推送系统管理员 2.延迟后仍校验失败，推送管理人员，转人工处理 3.首次推送后,有效价格校验失败，推送分供商
        private DataTable GetReqIdAndLoginId(DataRow drRequest, ref string strFlag, ref DataSet dst)
        {

            strFlag = "";
            AutoLog.Debug("GetReqIdAndLoginId-1", "开始校验询价单" + drRequest["RequestID"].ToString() + "的各报价单是否符合要求");
            DataTable dtResult = new DataTable();
            DataTable dt = new DataTable();
            DataTable dtCountResult = new DataTable();
            dtCountResult.Columns.Add("ReqDetailID");
            dtCountResult.Columns.Add("tauloginid");
            DataTable dtPriceResult = new DataTable();
            dtPriceResult.Columns.Add("ReqDetailID");
            dtPriceResult.Columns.Add("tauloginid");
            Dictionary<string, object> parm1 = new Dictionary<string, object>();
            try
            {
                
                string strSql = "";
                strSql = "select * from T_RequestDetail where RequestID='{0}'";
                strSql = string.Format(strSql, drRequest["RequestID"]);
                dt = da.ExecuteDataTable(strSql);

                ///获取每个子项，并循环校验
                foreach (DataRow drList in dt.Rows)
                {
                    //已延时汇总过了，逻辑变更
                    if (drRequest["rowstatus"].ToString() == "7")
                    {
                        parm1 = new Dictionary<string, object>();
                        parm1.Add("@ReqDetailID", drList["ReqDetailID"]);

                        //校验是否存在0条或者1条报价的情况
                        DataTable dtCount = da.GetDataTableBySPName("SP_CheckResponeCount", parm1);

                        //仍然校验失败，转人工处理
                        if (dtCount != null && dtCount.Rows.Count > 0)
                        {
                            //dtCountResult = ((DataTable)dtCount).Clone();
                            strSql = "";
                            strSql = "update T_RequestDetail set rowstatus=9 where ReqDetailID='{0}'";
                            strSql = string.Format(strSql, drList["ReqDetailID"]);
                            da.ExcuteNoQuery(strSql);

                            
                            foreach (DataRow dr2 in dtCount.Rows)
                            {

                                dtCountResult.ImportRow(dr2);
                            }

                            //dtCount.TableName = "dtCount";
                            //dst.Tables.Add(dtCount);

                            if (!strFlag.Contains("2"))
                            {
                                strFlag = strFlag + "2";
                            }
                            AutoLog.Debug("存在异常-3", strFlag);
                        }
                    }
                    else
                    {
                        parm1 = new Dictionary<string, object>();
                        parm1.Add("@ReqDetailID", drList["ReqDetailID"]);

                        //校验是否存在0条或者1条报价的情况
                        DataTable dtCount = da.GetDataTableBySPName("SP_CheckResponeCount", parm1);

                        //校验是否存在无效价格情况
                        DataTable dtPrice = da.GetDataTableBySPName("SP_CheckResponePrice", parm1);

                        if ((dtCount != null && dtCount.Rows.Count > 0) || (dtPrice != null && dtPrice.Rows.Count > 0))
                        {
                            strSql = "";
                            strSql = "update T_Request set rowstatus=7 where RequestID='{0}'";
                            strSql = string.Format(strSql, drRequest["RequestID"]);
                            da.ExcuteNoQuery(strSql);

                            if (dtCount != null && dtCount.Rows.Count > 0)
                            {
                                foreach (DataRow dr2 in dtCount.Rows)
                                {
                                    dtCountResult.ImportRow(dr2);
                                }
                                if (!strFlag.Contains("1"))
                                {
                                    strFlag = strFlag + "1";
                                }
                                AutoLog.Debug("存在异常-3", strFlag);
                            }
                            if (dtPrice != null && dtPrice.Rows.Count > 0)
                            {
                                foreach (DataRow dr2 in dtPrice.Rows)
                                {
                                    dtPriceResult.ImportRow(dr2);
                                }
                                if (!strFlag.Contains("3"))
                                {
                                    strFlag = strFlag + "3";
                                }
                                AutoLog.Debug("存在异常-4", strFlag);
                            }

                            //return dtCount;
                        }
                    }
                    
                }

                dtCountResult.TableName = "dtCount";
                dst.Tables.Add(dtCountResult);
                dtPriceResult.TableName = "dtPrice";
                dst.Tables.Add(dtPriceResult);

                //循环校验完毕，没有问题。正式挑选报价
                if (string.IsNullOrWhiteSpace(strFlag))
                {
                    strFlag = "0";
                    Dictionary<string, object> parm2 = new Dictionary<string, object>();
                    parm2.Add("@RequestID", drRequest["RequestID"]);
                    parm2.Add("@Rowstatus", drRequest["rowstatus"]);

                    AutoLog.Debug("GetReqIdAndLoginId-4", "校验通过，正式开始挑选报价单");

                    dtResult = da.GetDataTableBySPName("SP_ChoiceRespone", parm2);

                    AutoLog.Debug("GetReqIdAndLoginId-5", "结束校验询价单" + drRequest["RequestID"].ToString());
                    return dtResult;
                }
                else
                {
                    return dtResult;
                }
                
            }
            catch (Exception ex)
            {
                AutoLog.Debug("询价单" + drRequest["RequestID"].ToString() + "校验出错", ex.Message.ToString());
                return dtResult;
            }
        }

        /// <summary>
        /// ERP接口自动抓取数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                AutoLog.Debug("backgroundWorker3_DoWork", "开始运行");
                GetSupplierInfo();
                GetItemInfo();
                GetDemandInfo();
                Thread.Sleep(1000 * 60);
            }
            catch (Exception ex)
            {
                AutoLog.Debug("AutoService-backgroundWorker1_DoWork", ex.Message.ToString());
            }
        }

        /// <summary>
        /// 抓取供应商信息
        /// </summary>
        private void GetSupplierInfo()
        {
            //获取中间库供应商表有多少数据

            //循环供应商编号，与本地数据库比对，存在更新，不存在新增

            //将抓取过得数据，放入备份表，删除中间表数据
        }

        /// <summary>
        /// 抓取物料（子项）信息
        /// </summary>
        private void GetItemInfo()
        {
            //获取中间库物料（子项）表有多少数据

            //循环物料编号，与本地数据库比对，存在更新，不存在新增

            //将抓取过得数据，放入备份表，删除中间表数据
        }

        /// <summary>
        /// 抓取请购单
        /// </summary>
        private void GetDemandInfo()
        {
            //获取中间库请购单表有多少数据

            //循环请购单编号，插入本地数据库，进行发布

            //将抓取过得数据，放入备份表，删除中间表数据

            //根据物料编号找到对应供应商，生成对应报价单，并进行推送


        }
    }
}
